//-----------------------------------------------------------------------------
//	File: led.c
//	Author: hsia
//		bsp of led
//-----------------------------------------------------------------------------

#include "led.h"

#define LED_RCC_ALL		(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC)
#define LED_1_PORT		GPIOC
#define LED_1_PIN		GPIO_Pin_7
#define LED_2_PORT		GPIOC
#define LED_2_PIN		GPIO_Pin_8
#define LED_3_PORT		GPIOC
#define LED_3_PIN		GPIO_Pin_9
#define LED_4_PORT		GPIOA
#define LED_4_PIN		GPIO_Pin_8

//-----------------------------------------------------------------------------
//	configure_led_gpio - configure led gpio
//-----------------------------------------------------------------------------
void configure_led_gpio(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	// Enable the peripheral's clock
	RCC_APB2PeriphClockCmd(LED_RCC_ALL, ENABLE);
	// gpio default
	led_1(0);
	led_2(0);
	led_3(0);
	led_4(0);
	// gpio mode
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	// led pin seting
	GPIO_InitStructure.GPIO_Pin = LED_1_PIN;
	GPIO_Init(LED_1_PORT, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin = LED_2_PIN;
	GPIO_Init(LED_2_PORT, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin = LED_3_PIN;
	GPIO_Init(LED_3_PORT, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin = LED_4_PIN;
	GPIO_Init(LED_4_PORT, &GPIO_InitStructure);
}

//-----------------------------------------------------------------------------
//	led on off inv
//-----------------------------------------------------------------------------
void led_1(uint8_t sw)
{
	switch (sw) {
		case 0: LED_1_PORT->ODR &= ~LED_1_PIN; break;
		case 1: LED_1_PORT->ODR |= LED_1_PIN; break;
		case 2: LED_1_PORT->ODR ^= LED_1_PIN; break;
	}
}
void led_2(uint8_t sw)
{
	switch (sw) {
		case 0: LED_2_PORT->ODR &= ~LED_2_PIN; break;
		case 1: LED_2_PORT->ODR |= LED_2_PIN; break;
		case 2: LED_2_PORT->ODR ^= LED_2_PIN; break;
	}
}
void led_3(uint8_t sw)
{
	switch (sw) {
		case 0: LED_3_PORT->ODR &= ~LED_3_PIN; break;
		case 1: LED_3_PORT->ODR |= LED_3_PIN; break;
		case 2: LED_3_PORT->ODR ^= LED_3_PIN; break;
	}
}
void led_4(uint8_t sw)
{
	switch (sw) {
		case 0: LED_4_PORT->ODR &= ~LED_4_PIN; break;
		case 1: LED_4_PORT->ODR |= LED_4_PIN; break;
		case 2: LED_4_PORT->ODR ^= LED_4_PIN; break;
	}
}

